package main.scripts;
import java.awt.*;
import java.util.Random;

import javax.swing.JOptionPane;

import main.client;
import main.bots.Bot;
import main.bots.Script;
import main.hooks.RSObject;
import main.listeners.PaintListener;
import main.listeners.ServerMessageListener;


public class Mischief extends Script implements ServerMessageListener, PaintListener {
	
	public static int xCoord = 0;
	public static int yCoord = 0;
	public static int objectId = 0;
	public boolean toStop = false;
	public boolean autoSave = false;
	public int stallID = 0;
	public boolean startScript;
	public RSObject stall;
	private int testInt = 0;
	
	public void clickMyObject(RSObject obj) {
		atObject252(obj.getId(),obj.getX(),obj.getY());
	}
	
	@Override
	public boolean endCondition() {
		return toStop;
	}
	@Override
	public String[] getAuthors() {
		return new String[] { "Nenny Boy" };
	}
	@Override
	public double getVersion() {
	return 1.0;
	}
	@Override
	public int loop() {
		
		atObject252(stallID, 3423,3432);
		if(autoSave) {
		sendCommand("save");
		}
		return random(1000, 6000);
	}
	@Override
	public void onFinish() {
	debug("Thanks for using the MISCHIEF bot xD");
		
	}
	@Override
	public boolean onStart() {
		new GUIThieveBot().setVisible(true);
		while (!startScript) {
			wait(10);
		}
		
		return getMyClient() != null;
	}
	@Override
	public String getCategory() {
		return "CrisisX";
	}
	
	@Override
	public void serverMessageRecieved(String message) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public String getDescription() {
	return "EDDITTED!~" + getVersion();
	}
	@Override
	public String getScriptName() {
		// TODO Auto-generated method stub
		return "Mischief";
	}
	
 class GUIThieveBot extends javax.swing.JFrame {

	    /** Creates new form GUIThieveBot */
	    public GUIThieveBot() {
	        initComponents();
	    }

	    /** This method is called from within the constructor to
	     * initialize the form.
	     * WARNING: Do NOT modify this code. The content of this method is
	     * always regenerated by the Form Editor.
	     */
	    @SuppressWarnings("unchecked")
	    // <editor-fold defaultstate="collapsed" desc="Generated Code">
	    private void initComponents() {

	        jPanel1 = new javax.swing.JPanel();
	        jLabel5 = new javax.swing.JLabel();
	        background = new javax.swing.JPanel();
	        thieveButton = new javax.swing.JButton();
	        example = new javax.swing.JLabel();
	        stall = new javax.swing.JComboBox();
	        whichStall = new javax.swing.JLabel();
	        madeBy = new javax.swing.JLabel();
	        officialTitle = new javax.swing.JLabel();
	        autoSaveBox = new javax.swing.JCheckBox();

	        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
	        jPanel1.setLayout(jPanel1Layout);
	        jPanel1Layout.setHorizontalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 100, Short.MAX_VALUE)
	        );
	        jPanel1Layout.setVerticalGroup(
	            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGap(0, 100, Short.MAX_VALUE)
	        );

	        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
	        setTitle("Mr Mischief - CrisisX Thiever");
	        setAlwaysOnTop(true);
	        setBackground(new java.awt.Color(0, 0, 0));
	        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
	        getContentPane().add(jLabel5, java.awt.BorderLayout.PAGE_START);

	        background.setBackground(new java.awt.Color(0, 0, 0));

	        thieveButton.setText("Thieve Me Away!!!");
	        thieveButton.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	                thieveButtonActionPerformed(evt);
	            }
	        });

	        example.setForeground(new java.awt.Color(255, 255, 255));
	        example.setText("stall name, amount earned per click, required level");

	        stall.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Silk Stall - 25k ea, Level 1+", "Silver Stall - 50k ea, Level 50+", "Gem Stall - 100k ea, Level 80+" }));

	        whichStall.setForeground(new java.awt.Color(255, 255, 255));
	        whichStall.setText("Which Stall: ");

	        madeBy.setFont(new java.awt.Font("Tahoma", 1, 11));
	        madeBy.setForeground(new java.awt.Color(255, 255, 255));
	        madeBy.setText("Made by NeN");

	        officialTitle.setFont(new java.awt.Font("Arial", 1, 18));
	        officialTitle.setForeground(new java.awt.Color(255, 255, 255));
	        officialTitle.setText("Mr Mischief - CrisisX Thieving Bot");

	        autoSaveBox.setBackground(new java.awt.Color(0, 0, 0));
	        autoSaveBox.setForeground(new java.awt.Color(255, 255, 255));
	        autoSaveBox.setText("Auto-save?");

	        javax.swing.GroupLayout backgroundLayout = new javax.swing.GroupLayout(background);
	        background.setLayout(backgroundLayout);
	        backgroundLayout.setHorizontalGroup(
	            backgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(backgroundLayout.createSequentialGroup()
	                .addGroup(backgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(backgroundLayout.createSequentialGroup()
	                        .addContainerGap()
	                        .addComponent(whichStall, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                        .addComponent(stall, 0, 172, Short.MAX_VALUE)
	                        .addGap(53, 53, 53))
	                    .addGroup(backgroundLayout.createSequentialGroup()
	                        .addGap(121, 121, 121)
	                        .addComponent(madeBy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addGap(111, 111, 111))
	                    .addGroup(backgroundLayout.createSequentialGroup()
	                        .addGap(99, 99, 99)
	                        .addComponent(thieveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                        .addGap(82, 82, 82)))
	                .addGap(23, 23, 23))
	            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundLayout.createSequentialGroup()
	                .addGap(23, 23, 23)
	                .addComponent(officialTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                .addContainerGap())
	            .addGroup(backgroundLayout.createSequentialGroup()
	                .addGap(37, 37, 37)
	                .addComponent(example, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                .addGap(49, 49, 49))
	            .addGroup(backgroundLayout.createSequentialGroup()
	                .addGap(115, 115, 115)
	                .addComponent(autoSaveBox)
	                .addContainerGap(131, Short.MAX_VALUE))
	        );
	        backgroundLayout.setVerticalGroup(
	            backgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundLayout.createSequentialGroup()
	                .addContainerGap()
	                .addComponent(officialTitle)
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
	                .addComponent(madeBy)
	                .addGap(24, 24, 24)
	                .addGroup(backgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	                    .addGroup(backgroundLayout.createSequentialGroup()
	                        .addGap(6, 6, 6)
	                        .addComponent(whichStall))
	                    .addComponent(stall, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
	                .addComponent(example, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
	                .addGap(1, 1, 1)
	                .addComponent(autoSaveBox, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
	                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                .addComponent(thieveButton, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
	                .addContainerGap())
	        );

	        getContentPane().add(background, java.awt.BorderLayout.CENTER);

	        pack();
	    }// </editor-fold>

	    private void thieveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
	        // TODO add your handling code here:
	        if(stall.getSelectedItem() == "Silver Stall - 50k ea, Level 50+") {
	        	stallID = 2565;
	        }
	        if(stall.getSelectedItem() == "Gem Stall - 100k ea, Level 80+") {
	        	stallID = 2562;
	        } else {
	        	stallID = 2560;
	        }
	        
	        if(autoSaveBox.isSelected()) {
autoSave = true;
	        }
	        setVisible(false);
	        startScript = true;
	    }                                            


	    // Variables declaration - do not modify
	    private javax.swing.JCheckBox autoSaveBox;
	    private javax.swing.JPanel background;
	    private javax.swing.JLabel example;
	    private javax.swing.JLabel jLabel5;
	    private javax.swing.JPanel jPanel1;
	    private javax.swing.JLabel madeBy;
	    private javax.swing.JLabel officialTitle;
	    private javax.swing.JComboBox stall;
	    private javax.swing.JButton thieveButton;
	    private javax.swing.JLabel whichStall;
	    // End of variables declaration

	}

@Override
public boolean onRepaint(Graphics g) {
	if(g == null) {
		debug("Graphics null");
		return true;
	}
	g.setColor(Color.RED);
    g.drawString("Pest Control: " + testInt, 100, 100);
    testInt++;
    System.out.println("Painted2");
	return true;
}


}
